<template>
  <div>
    <div>
      <span>项目编号:</span>
      <el-input
        style="width: 200px; margin: 0 0 0 0.5vw"
        v-model="queryForm.projectCode"
        placeholder="请输入内容"
        size="small"
      ></el-input>
      <span style="margin: 0 0 0 1vw">项目名称:</span>
      <el-input
        style="width: 200px; margin: 0 0 0 0.5vw"
        v-model="queryForm.projectName"
        placeholder="请输入内容"
        size="small"
      ></el-input>
      <span v-if="type == '10'" style="margin: 0 0 0 1vw">项目负责人:</span>
      <el-input
        v-if="type == '10'"
        style="width: 200px; margin: 0 0 0 0.5vw"
        v-model="queryForm.projectPerson"
        placeholder="请输入内容"
        size="small"
      ></el-input>
      <el-button
        type="primary"
        size="small"
        style="margin: 0 0 0 1vw"
        @click="search"
        >查询</el-button
      >
      <el-button
        type="primary"
        size="small"
        style="margin: 0 0 0 1vw"
        @click="add"
        >新增</el-button
      >
    </div>
    <div style="margin: 0.5vw 0">
      <span>起始时间:</span>
      <el-date-picker
        v-model="queryForm.startTime"
        style="width: 200px; margin: 0 0 0 0.5vw"
        placeholder="选择日期时间"
        value-format="yyyy-MM-dd"
        type="date"
        size="small"
      >
      </el-date-picker>
      <span style="margin: 0 0 0 1vw">结束时间:</span>
      <el-date-picker
        v-model="queryForm.endTime"
        style="width: 200px; margin: 0 0 0 0.5vw"
        placeholder="选择日期时间"
        type="date"
        value-format="yyyy-MM-dd"
        format="yyyy-MM-dd"
        size="small"
      >
      </el-date-picker>
    </div>
    <dialog-view
      :show="show"
      @shows="shows"
      :title="title"
      @refresh="refresh"
    />
    <addDraf :drafVisible="drafVisible" :title="title" @drafClose="drafClose" />
  </div>
</template>

<script>
import dialogView from "./dialogView.vue";
import addDraf from "./addDraf.vue";
export default {
  /* type判断是已创建还是草稿 */
  props: ["active", "clearText",'type'],
  data() {
    return {
      queryForm: {
        projectCode: "",
        projectName: "",
        projectPerson: "",
        startTime: "",
        endTime: "",
      },
      show: false,
      title: "",
      drafVisible: false,
    };
  },
  components: {
    dialogView,
    addDraf,
  },
  watch: {
    clearText(newV) {
      if (newV) {
        this.clearqueryForm();
      }
    },
  },
  methods: {
    search() {
      console.log(this.active, "av");
      this.$parent.pag.pageNo = 1;
      this.$emit("searches", this.queryForm);
    },
    //新增
    add() {
      if (this.active == "已创建") {
        this.show = true;
        this.title = "项目-添加";
      } else if (this.active == "草稿箱") {
        this.drafVisible = true;
        this.title = "草稿-添加";
      }
    },
    shows(e) {
      this.show = e;
    },
    refresh(e) {
      if (e == true && this.active) {
        this.$parent.pag.pageNo = 1;
        this.$parent.getlist({ pageNo: this.$parent.pag.pageNo, pageSize: 5 });
        this.show = false;
      }
    },
    //清理搜索
    clearqueryForm() {
      for (let key in this.queryForm) {
        this.queryForm[key] = "";
      }
      this.$nextTick(() => {
        this.$emit("clearOver", true);
      });
    },
    //关闭草稿
    drafClose(e) {
      if (e == true) {
        this.drafVisible = false;
        this.$emit("drafRefresh", true);
      }
    },
  },
};
</script>

<style scoped>
</style>